const sequelize = require('../connection');
const { DataTypes } = require("sequelize");
//
const moment = require('moment');
// import { DataTypes } from "sequelize";
// import { sequelize  } from '../connection';
// console.log("sequelize", sequelize);

const News = sequelize.define(
    "news",
    {
    news_id: {
        type: DataTypes.INTEGER,
        primaryKey: true,
        allowNull: true,
        autoIncrement: true
    },
    title: {
        type: DataTypes.STRING,
        allowNull: false
    },
    content: {
        type: DataTypes.STRING,
        allowNull: false
    },
    category_id:{
        type: DataTypes.INTEGER,
        allowNull: false,
        defaultValue: '0',
    },
    // 创建时间
    publish_time: {
        type: DataTypes.DATE,
        defaultValue: new Date(),
        get() {
            return moment(this.getDataValue('publish_time')).format('YYYY-MM-DD HH:mm:ss');
        }
    },
   status:{
            type: DataTypes.INTEGER,
            allowNull: false,
            defaultValue: '1',
            comment: "1 0",
        },
    created_by: {
        type: DataTypes.INTEGER,
        allowNull: false,
        defaultValue: '0',
    }
}, {
    // timestamps: true,
    // createdAt: false,
        timestamps: false,
        tableName: 'news'
})

// Article.sync()


// !(async function () {
//     const sange = await News.create({
//             "title":"company news - new policy",
//             "content":"new policy new policynew policynew policynew policynew policynew policy",
//             "category_id":2,
//             "created_by": 2
//         });
//     console.log(sange)
// })()

module.exports = News;

// const test = () => {
//     return  new Promise((resolve, reject) => {
//         const res = News.created({
//             "title":"company news - new policy",
//             "content":"new policy new policynew policynew policynew policynew policynew policy"
//         });
//         resolve(res);
//     })
//
// }
//
// console.log(test());

